from django.shortcuts import render,redirect
from django.shortcuts import render
from django.http import FileResponse
from django.views.decorators.csrf import csrf_exempt
from django.http import HttpResponse,Http404
import json
from GPT.functions import teacherModel

def login(request):
    return HttpResponse("Hello, world. You're at the admin page.")

# render测试用例
def rendertest(request):
    return render(request, 'login.html')

# redirect测试用例
def redirecttest(request):
    return redirect('https://www.bilibili.com/video/BV14k4y1h7o9?p=7&vd_source=541c8681184ebba32e2a524ae8d60d85')

@csrf_exempt
def teacher_model(request):
    if request.method == 'POST':
        data = json.loads(request.body.decode('utf-8'))  # 解析请求数据为JSON格式
        #print(data)
        text = data['question']  # 提取"question"字段的值
        type = data['type']
        # 调用函数
        answer = teacherModel.teacher_model(text,type)
        return HttpResponse(answer)

@csrf_exempt
def set_role(request):
    if request.method == 'POST':
        data = json.loads(request.body.decode('utf-8'))  # 解析请求数据为JSON格式
        #print(data)
        role = data['role']  # 提取"question"字段的值
        # 调用函数
        teacherModel.role_of_teacher(role)
        return HttpResponse()